package cn.zyzpp.util;

import javax.servlet.http.HttpSession;
import java.util.regex.Pattern;

/**
 * Create by yster@foxmail.com 2018/5/22/022 0:41
 */
public class StringUtil {
    private static String symbol = "(\r\n|\r|\n|\n\r)";
    private static String line = "<br>";

    public static int getIntByString(Object s){
        String i = Pattern.compile("[^0-9]").matcher(s.toString()).replaceAll("");
        return Integer.parseInt(i);
    }
    public static int getIntBySessionUid(HttpSession session){
        try {
            String i = Pattern.compile("[^0-9]").matcher(session.getAttribute("uid").toString()).replaceAll("");
            return Integer.parseInt(i);
        }catch (Exception e){
            return 0;
        }
    }

    public static String symline(String s){
        return s.replaceAll(symbol, line);
    }

}
